package com.food.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.food.dao.service.ApplicationService;
import com.food.dao.service.CourseService;
import com.food.dao.service.MbproductService;
import com.food.dao.service.ProductService;
import com.food.model.Application;
import com.food.model.Course;
import com.food.model.Mbproduct;
import com.food.model.Member;
import com.food.model.Product;

@WebServlet("/member/MyProduct")
public class MyProduct extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		MbproductService mbproductService = new MbproductService();
		ProductService productService = new ProductService();
		
		HttpSession session = request.getSession();
		Member member = (Member)session.getAttribute("user");
		
		Mbproduct mbproduct = new Mbproduct();
		mbproduct.setMbid(member.getMbid());
		List<Mbproduct> list = mbproductService.findProductByMb(mbproduct);
		List<Product> coll = new ArrayList<Product>();
		for(Mbproduct mp:list){
			Product product = new Product();
			product = productService.findOneProduct(mp.getPid());
			coll.add(product);
			
		}
		request.setAttribute("mbproduct", coll);
		RequestDispatcher rd = request
				.getRequestDispatcher("/member/myproduct.jsp");
		rd.forward(request, response);
		return;
	}

}
